#!/bin/bash

# release on Kloxo 6.1.7
# by mustafa.ramadhan@lxcenter.org

# ENVIRONMENT VARIABLE PRIMER FOR REFERENCE
# $0 script invoked
# $1, $2, $3 are the command line arguments
# $# Number of command line arguments 
# $@ all command line arguments - white space is preserved
# $* all command line arguments - white space striped 

# not exist in openvz vps
# grubfile="/boot/grub/grub.conf"
proc__user_beancounters="/proc/user_beancounters"


# if [ -f $grubfile ]; then

if [ ! -f $proc__user_beancounters ]; then
	if [ "$1" == "--select=1" ]; then
		sync; echo 1 > /proc/sys/vm/drop_caches
	elif [ "$1" == "--select=2" ]; then
		sync; echo 2 > /proc/sys/vm/drop_caches
	elif [ "$1" == "--select=3" ]; then
		sync; echo 3 > /proc/sys/vm/drop_caches
	else
		echo
		echo " ----------------------------------------------------"
		echo "  format: sh $0 --select=<1/2/3>"
		echo " ----------------------------------------------------"
		echo "  ---select: 1 = pagecache, 2 = dentries+inodes, 3 = all"
		echo
		echo " * no effect for Openvz VPS"
		echo
		exit;
	fi
else
	if [ "$2" != "--silent" ]; then
		echo
		echo "Not work on OpenVZ VPS"
		echo
	fi
fi

